// 循环队列 
import Queue from './queue'
/**
 * @description: 击鼓传花 函数功能 
 * @param  {Array<T> }  传花的元素数组
 * @param {number}每次传花的次数
 * @return  返回winner 离开的数组
 */

interface HotPotatoResult<T> {
    winner: T;
    elimated: Array<T>;
}

function hotPotato<T>(
    // 1. 把数组入队 完成特定问题的ADT选型
    // 2. 调用ADT 方法 完成业务
    elementsList: Array<T>,
    num: Number
): HotPotatoResult<T> {
    const queue: Queue<T> = new Queue();
    const elimitatedList: Array<T> = [];

    // 入队操作
    for (let i = 0, len = elementsList.length; i < len; i++) {
        queue.enqueue(elementsList[i])
    }
    while (queue.size() > 1) {
        for (let i = 1; i < num; i++) {
            queue.enqueue(queue.dequeue())
        }
        elimitatedList.push(queue.dequeue() as T)
    }
    return {
        elimated: elimitatedList,
        winner: queue.dequeue() as T
    }
}

const names = ['刘思浪', '谢包发', '白胡子', '红发', '大妈', '黑胡子'];

console.log(hotPotato(names, 6))